<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <style>
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        .jc{
            background-color: plum;
            position: fixed;
            width: 100%;
            height: 60px;
            top: 0px;
            transition: all 1s;
        }
        .one{
            width: 1000px;
            height: 300px;
            background-color: rebeccapurple;
            margin: auto;
        }
        .two{
            width: 1000px;
            height: 300px;
            background-color: rgb(198, 174, 222);
            margin: auto;
        }
        
        .three{
            width: 1000px;
            height: 450px;
            background-color: tan;
            margin: auto;
            position: relative;
        }
        ul{
            border:1px solid black;
            list-style: none;
            position: absolute;
            width: 50px;
            height: 200px;
            background-color: cornflowerblue;
            left: 50%;
            margin-left: 520px;
        }
        .five{
            width: 1000px;
            height: 1000px;
            background-color: tan;
            margin: auto;
        }
        .four{
            width: 1000px;
            height: 400px;
            background-color: rgb(60, 162, 60);
            margin: auto;
        }
        button{
            position: fixed;
            bottom: 0;
            left: 50%;
        }
    </style>
</head>
<body>
    <div class="jc"></div>
    <div class="one"></div>
    <div class="two">
    </div>
    <div class="three">
        <ul></ul>
    </div>
    <div class="four"></div>
    <div class="five"></div>
    <script>
        let jc = document.querySelector('.jc');
        let one = document.querySelector('.one');
        let four = document.querySelector('.four');
        let three = document.querySelector('.three');
        let five = document.querySelector('.five');
        let ul = document.querySelector('ul');

        console.log(jc.offsetHeight);
        console.log(four);
        window.addEventListener('scroll',function(){
            let sc = window.pageYOffset;
            console.log(sc)
            if(sc > four.offsetTop){
                jc.style.top=0+'px';
            }else{
                jc.style.top=-60+'px';
            }
            if(sc >=  three.offsetTop){
                ul.style.position = 'fixed';
                ul.style.top = 66+'px';
                five.innerHTML='<button onclick="add()">点击回到顶部</button>'
            }else if(sc <= three.offsetTop){
                ul.style.position = 'absolute';
                ul.style.top = 0+'px';
                five.innerHTML='<button onclick="odd()">点击回到底部</button>';
            }
        })
        function add(){
            document.documentElement.scrollTop = 0;
        }
        function odd(){
            document.documentElement.scrollTop = five.offsetHeight+1000;
        }
        //节流
        function throttlr(fn,delay){
            let valid = true;
            return function(){
                if(!valid){
                    return false
                }
                valid = false;
                setTimeout(()=>{
                    fn()
                    valid = true;
                },delay)
            }
        }
    </script>
</body>
</html>